/**
 * @file
 * @author
 * @date
 * @brief
 */

#ifndef __DISPLAY_DRV_H___
#define __DISPLAY_DRV_H___
#include "stdint.h"
#ifndef OLED_SIZE_X
    #define OLED_SIZE_X (240)
#endif
#ifndef OLED_SIZE_Y
    #define OLED_SIZE_Y (240)
#endif    
#ifndef OLED_RAM_Y_MAX
    #define OLED_RAM_Y_MAX (320)
#endif    

#define OLED_BUFF_SIZE (OLED_SIZE_X * OLED_SIZE_Y * 2)

#define RGB565_COLOR_BLACK 0x0000
#define RGB565_COLOR_WHITE 0xFFFF
#define RGB565_COLOR_RED 0xF800
#define RGB565_COLOR_BLUE 0x051D
#define RGB565_COLOR_PINK 0xFD79
#define RGB565_COLOR_GRAY 0xC618
#define RGB565_COLOR_GREEN 0x07E0
#define RGB565_COLOR_YELLO 0xFF80

#define RGB565_COLOR_ORANGE 0Xf421
#define RGB565_COLOR_LIGHT_BLUE 0X6e7d

#define RGB565_GET_COLOR_R(color) (((uint16_t)color >> 11) & 0x1F)
#define RGB565_GET_COLOR_G(color) (((uint16_t)color >> 5) & 0x3F)
#define RGB565_GET_COLOR_B(color) ((uint16_t)color & 0x1F)
#define RGB565(R, G, B) ((((R) << 8) & (0xF800)) | (((G) << 3) & (0x07E0)) | (((B) >> 3) & 0X1F))

typedef unsigned char disp_xy_t;

typedef enum
{
    SPI_CFG_MODE_HARDWARE,
    SPI_CFG_MODE_SOFTWARE,
    SPI_CFG_MODE_HARDWARE_DMA,
} spi_cfg_mode_t;

void lcd_drv_init(void);
void lcd_set_ram_offset(uint16_t offset);
void lcd_set_xy(uint16_t Xstart, uint16_t Xend, uint16_t Ystart, uint16_t Yend);
void oled_fill_data(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *p_data);
void oled_fill_data_continue(uint16_t w, uint16_t h, const uint8_t *p_data);
void oled_spi_tx_color(uint16_t data);
void oled_spi_wait_end(void);
void oled_turn_on(void);
void oled_turn_off(void);
void oled_reset_clear(void);
void oled_all_fill_data(uint16_t data);
uint8_t oled_spi_get_mode(void);
void oled_spi_init(spi_cfg_mode_t spi_cfg_mode);

void oled_write_cmd(uint8_t cmd);
void oled_write_data_bytes(uint8_t *p_data, uint16_t len);
void oled_spi_tx_byte(uint8_t data);
void spim_tx(const uint8_t *p_buffer, uint8_t length, uint16_t auto_dma_times);
void oled_spi_tx_bytes_hw(const uint8_t *p_data, uint16_t length);
void oled_spi_hw_wait_end(void);
void spi_switch_mode(uint8_t config_mode);
void oled_write_data(uint8_t data);
// #define SPI_DEFAULT_MODE SPI_CFG_MODE_HARDWARE_DMA
int get_spi_mode(void);
#endif
